package com.github.prontera.controller;

import java.time.OffsetDateTime;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.github.prontera.ApiVersion;
import com.github.prontera.RequestLogging;
import com.github.prontera.domain.AppVersion;
import com.github.prontera.model.response.ObjectDataResponse;
import com.github.prontera.service.AppVersionService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;


/**
 * 版本管理
 */
@RestController
@Api(value = "版本更新接口")
@RequestMapping(value = ApiVersion.API_V1_PREFIX+"/version")
public class AppVersionController{
	
	@Autowired
	private AppVersionService appVersionService;
	
	 /**
     * 查找最新版本的APP
     */
	
    @RequestMapping(value = "findNewVersion", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "查找最新版本的APP", notes = "")
    public ObjectDataResponse<AppVersion> findNewVersion(@ApiParam(name = "client", value = "客户端：0：安卓,1：IOS", required = true) @RequestBody Integer client) {
        AppVersion appVersion = new AppVersion();
        appVersion.setClient(client);
        appVersion.setStartUseTime(OffsetDateTime.now());
        appVersion.setOrderBy("APP_VERSION.start_use_time desc");
        appVersion.setPageIndex(0);
        appVersion.setPageSize(1);
        AppVersion datas = appVersionService.findOne(appVersion);
        return new ObjectDataResponse<AppVersion>(datas);
    }
	 
}
